package com.zhx.real.mybatisplus.util;


import org.apache.commons.lang.StringUtils;

import javax.validation.Validation;
import javax.validation.Validator;


/**
 * 数据校验
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-03-23 15:50
 */
public class Assert {
    private static Validator validator;

    static {
        validator = Validation.buildDefaultValidatorFactory().getValidator();
    }

    public static void isBlank(String str, String message) {
        if (StringUtils.isBlank(str)) {
            throw new CheckedException(message);
        }
    }

    public static void isNull(Object object, String message) {
        if (object == null) {
            throw new CheckedException(message);
        }
    }

	public static void isNotNull(Object object, String message) {
		if (object != null) {
			throw new CheckedException(message);
		}
	}

    public static void isEqual(String var1,String var2,String message){
        if(var1.equals(var2)){
            throw new CheckedException(message);
        }
    }

    public static void isNotEqual(String var1,String var2,String message){
        if(!var1.equals(var2)){
            throw new CheckedException(message);
        }
    }

	public static void isTrue(boolean var1,String message){
		if(var1){
			throw new CheckedException(message);
		}
	}

    public static void isBig(int var1,int var2,String message){
        if(var1 > var2){
            throw new CheckedException(message);
        }
    }
}
